package com.example.config.modbus;

import com.serotonin.modbus4j.BasicProcessImage;

/**
 * @Author 郅占伟
 * @ClassName Register
 * @Description TODO
 * @Date 2024年07月30日
 * @Version: 1.0
 */
public class Register {
    public static BasicProcessImage getModbusProcessImage(int slaveId) {
        // 初始化过程影像区
        BasicProcessImage processImage = new BasicProcessImage(slaveId);

        // 初始化寄存器数据范围
        processImage.setInvalidAddressValue(Short.MIN_VALUE);

        // 初始化过程影响区各个数值的初始值为0
        for (int i = 0; i < 1000; i++) {
            processImage.setHoldingRegister(i, (short) 0);
        }
        processImage.addListener(new BasicProcessImageListener());
        return processImage;
    }
}
